<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />

<title>Decoupling Patterns &middot; Game Programming Patterns</title>

<!-- Tell mobile browsers we're optimized for them and they don't need to crop
     the viewport. -->
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" type="text/css" href="style.css" />
<link href="https://fonts.googleapis.com/css?family=Merriweather:400,400italic,700,700italic|Source+Code+Pro|Source+Sans+Pro:200,300,400,600,400italic,600italic|Rock+Salt" rel="stylesheet" type="text/css">
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-42804721-1', 'gameprogrammingpatterns.com');
  ga('send', 'pageview');
</script>
<script src="jquery-3.6.0.min.js"></script>
<script src="script.js"></script>
</head>
<body id="top">
<div class="page sidebar">
<div class="content">
<nav class="top">
  <span class="prev">&larr; <a href="type-object.html">Previous Chapter</a></span>
  <span class="next"><a href="component.html">Next Chapter</a> &rarr;</span>
  <span class="toc">&equiv; <a href="/">The Book</a></span>
</nav>
<h1>Decoupling Patterns</h1>
<h1 class="book"><a href="/">Game Programming Patterns</a></h1>
<p>Once you get the hang of a programming language, writing code to do what you
want is actually pretty easy. What&#8217;s hard is writing code that&#8217;s easy to adapt
when your requirements <em>change</em>. Rarely do we have the luxury of a perfect
feature set before we&#8217;ve fired up our editor.</p>
<p>A powerful tool we have for making change easier is <em>decoupling</em>. When we say
two pieces of code are &#8220;decoupled&#8221;, we mean a change in one usually doesn&#8217;t
require a change in the other. When you change some feature in your game, the
fewer places in code you have to touch, the easier it is.</p>
<p><a href="component.html">Components</a> decouple different domains in your game from each
other within a single entity that has aspects of all of them. <a href="event-queue.html">Event
Queues</a> decouple two objects communicating with each other,
both statically and <em>in time</em>. <a href="service-locator.html">Service Locators</a> let
code access a facility without being bound to the code that provides it.</p>
<h2><a href="#the-patterns" name="the-patterns">The Patterns</a></h2>
<ul>
<li><a href="component.html">Component</a></li>
<li><a href="event-queue.html">Event Queue</a></li>
<li><a href="service-locator.html">Service Locator</a></li>
</ul>
<nav>
  <span class="prev">&larr; <a href="type-object.html">Previous Chapter</a></span>
  <span class="next"><a href="component.html">Next Chapter</a> &rarr;</span>
  <span class="toc">&equiv; <a href="/">The Book</a></span>
</nav>
</div>
</div>
<footer>&copy; 2009-2021 Robert Nystrom</footer>
</body>
</html>
